<template>
	<view class="item" :class="{readed: readHistory.find(o=> o===story.id)}" @click="navToDetail(story.id)">
		<view class="story">
			<view class="title">{{story.title}}</view>
			<view class="con">{{story.hint}}</view>
		</view>
		<image :src="story.images[0]" :lazy-load="true" class="thumb"></image>
	</view>
</template>

<script>
	export default {
		name: "StoryItem",
		props: ['story'],
		data() {
			return {
				readHistory: uni.getStorageSync('ReadHistory') || [],
			};
		},
		methods: {
			navToDetail: function(id) {
				// console.log(uni.getStorageSync('ReadHistory') || [], id);
				const old = uni.getStorageSync('ReadHistory') || [];
				if (old.indexOf(id)) {
					console.log('no')
					old.push(id);
				} else {
					console.log(old.indexOf(id))
				}
				uni.setStorageSync('ReadHistory',old);
				this.readHistory = [id, ...this.readHistory];
				// uni.setStorageSync("ReadHistory", this.readHistory);
				uni.navigateTo({
					url: "../../pages/detail/detail?id=" + id
				})
			}
		}
	}
</script>

<style lang="less">
	.item {
		display: flex;
		align-items: center;
		margin: 30rpx;

		&.readed {
			color: #aaaaaa;
		}

		.story {
			flex: 1;

			.title {
				font-size: 30rpx;
				font-weight: bold;
				max-width: 520rpx;
			}

			.con {
				font-size: 20rpx;
				color: #aaaaaa;
				line-height: 3em;
			}
		}

		.thumb {
			width: 120rpx;
			height: 120rpx;
			border-radius: 6rpx;

		}
	}
</style>
